#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=4e5+5;
int n,T,q[N];
set<int> s;
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>T;
	int x;
	while(T--) {
		cin>>x;
		if(s.count(x))
			s.erase(x);
		else s.insert(x);
		n=0;
		for(auto i:s) {
			q[++n]=i;
		}
		int sum1=0,sum2=0;
		int last=0,ans=0;
		for(int i=1;i<=n;i++) {
			sum1+=q[i],sum2+=q[n-i+1];
			ans+=sum2-max(last,sum1);
			last=sum2;
		}
		cout<<ans<<"\n";
	}
	return 0;
}
/*
6
2
4
1
5
3
4
*/
